#!/bin/zsh

alias crl='curl --cacert ~/DEF/ctf/ca/ca.crt -E ~/DEF/ctf/clients/blue-lotus/blue-lotus.crt --key ~/DEF/ctf/clients/blue-lotus/blue-lotus.key'
while :; do
  timer=$(crl -sS https://10.3.1.7/timers)
  round=$(date -d $(jq -r .timers.round <<< "$timer") +%s)
  now=$(date -d $(jq -r .time <<< "$timer") +%s)
  sec=$((round-now))
  crl https://10.3.1.7/scoreboard.json | jq -r '.generated_at as $g | .standings[] | "\($g)\t\(.team)\t\(.score)"' >> ~/DEF/scoreboard/data/rank.day3.tsv
  if [[ $sec -gt 0 ]]; then
    sleep $sec
  fi
done
